// 封装request请求
// let flge = true
uni.setStorageSync("showModalBool", true);
const request = param => {
    // console.log(param);

    // let that = this;
    let token = uni.getStorageSync("token");
    let showModalBool = uni.getStorageSync("showModalBool");

    // let token = uni.getStorageSync("wxtoken");
    // if (!token) {
    //     console.log("------------没有token?")
    //     uni.navigateTo({
    //         url: "../../pages/login/login"
    //     });
    // }
    // const baseURL = "http://yaolu.dev.lanlnk.com/platform/";
    const baseURL = "https://yl.solid-cn.com/platform/";
    return new Promise((resolve, reject) => {
        uni.request({
            method: param.method || "GET",
            header: {
                Accept: "application/json",
                xcx: 1,
                Authorization: `Bearer ${token}`
            },
            ...param,
            url: baseURL + param.url,
            success: res => {
                //请求成功resolve
                resolve(res);
                if (res.data.errorcode === 405) {
                    let showModalBool = uni.getStorageSync("showModalBool");
                    if (showModalBool) {
                        uni.setStorageSync("showModalBool", false);
                        uni.showModal({
                            content: res.data.messages,
                            showCancel: false,
                            success: function(res) {
                                console.log(res);
                                if (res.confirm) {
                                    uni.clearStorage();
                                    uni.setStorageSync("showModalBool", true);
                                    uni.reLaunch({
                                        url: "../../pages/login/login"
                                    });
                                } else if (res.cancel) {
                                    uni.setStorageSync("showModalBool", true);  
                                }
                            }
                        });
                        
                    }
                } else if(res.statusCode == 429) {
                    uni.showToast({
                        title: '频繁操作,请稍后操作',
                        icon: 'none',
                        duration: 2000
                    });
                }
            },
            fail: err => {
                reject(err);
            },
        });
    });
};
//导出封装模块
module.exports = {
    request
};
